package com.slipper.system.codeless.service;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;

import com.slipper.system.codeless.dao.AppDao;
import com.slipper.system.codeless.bo.AppBO;

import com.slipper.core.transaction.ReadTransactional;
import com.slipper.core.transaction.WriteTransactional;
import com.slipper.util.Tool;
import com.slipper.util.UUID;

@Service
@ReadTransactional
public class AppService {
    @Resource
    private AppDao appDao;
    
    public AppBO queryBy(String id) {
        return appDao.queryBy(id);
    }
    
    public List<AppBO> queryList(AppBO bo) {
        return appDao.queryList(bo);
    }
    
    public PageInfo<AppBO> queryPage(AppBO bo) {
        PageHelper.startPage(bo.getPageNumber(), bo.getPageSize());
        return new PageInfo<>(appDao.queryList(bo));
    }
    
    @WriteTransactional
    public int save(AppBO bo) {
        if (Tool.isNotBlank(bo.getId())) {
            bo.setUpdateTime(System.currentTimeMillis());
            return appDao.update(bo);
        } else {
            bo.setId(UUID.getUUID());
            bo.setUpdateTime(System.currentTimeMillis());
            bo.setCreateTime(System.currentTimeMillis());
            return appDao.insert(bo);
        }
    }
    
    @WriteTransactional
    public int delete(AppBO bo) {
        return appDao.delete(bo);
    }
}
